﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp3
{
    /// <summary>
    /// 墙类
    /// </summary>
    class Wall
    {
        public Rectangle Rectangle { get; set; }

        //定义两个矩形
        public Rectangle Rectangle1;
        public Rectangle Rectangle2;
        public Rectangle newRectangle1;
        public Rectangle newRectangle2;

        //定义常量墙移动速度
        private const int SpeedX = -10;

        public Wall(Rectangle rec)
        {            
            //获取参数
            Rectangle = rec;
            //获取随机数
            int i;
            Random random = new Random();
            i = random.Next(70, 130);
            //定义两个矩形的属性
            Rectangle1 = new Rectangle(Rectangle.X, 0, Rectangle.Width, i);
            Rectangle2 = new Rectangle(Rectangle.X, i + 130, Rectangle.Width, 333 - i - 130);
        }

        /// <summary>
        /// 绘制墙
        /// </summary>
        /// <param name="g"></param>
        public void Drawcactus(Graphics g)
        {            
                g.DrawImage(Properties.Resources.cactusdown, Rectangle1);
                g.DrawImage(Properties.Resources.cactusup, Rectangle2);
        }

        public void Drawice(Graphics g)
        {
            g.DrawImage(Properties.Resources.ice, Rectangle1);
            g.DrawImage(Properties.Resources.ice, Rectangle2);
        }

        //墙的移动函数
        public void WallMove()
        {
            this.newRectangle1 = new Rectangle(this.Rectangle1.X + SpeedX+10, this.Rectangle1.Y, Rectangle1.Width-16, Rectangle1.Height-4);
            this.Rectangle1 = new Rectangle(this.Rectangle1.X + SpeedX, this.Rectangle1.Y, Rectangle1.Width, Rectangle1.Height);
            this.Rectangle2 = new Rectangle(this.Rectangle2.X + SpeedX, this.Rectangle2.Y, Rectangle2.Width, Rectangle2.Height);
            this.newRectangle2 = new Rectangle(this.Rectangle2.X + SpeedX+10, this.Rectangle2.Y+4, Rectangle2.Width-16, Rectangle2.Height);
        }

        

        //处理碰墙
        public bool HandleTouch(Rectangle rectangle)
        {
            if (rectangle.IntersectsWith(newRectangle1)| rectangle.IntersectsWith(newRectangle2))
            {              
                return true;
            }
            else
            {
                return false;
            }
        }

        //处理墙到边界的移除
        public bool WallRemove()
        {
            if (Rectangle1.X<0|Rectangle2.X<0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

    }
}
